#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
void game()
{
	int  r = rand() % 100 + 1;
	int guess = 0;
	int count = 5;
	while (1)
	{
		printf("请输入你的数字\n");
		scanf("%d", &guess);
		if (guess > r)
			printf("大了\n");
		else if (guess < r)
			printf("小了\n");
		else
		{
			printf("恭喜你猜中了");
			break;
		}
		count--;
		printf("你还剩下%d次机会\n", count);
		if (count == 0)
		{
			printf("你失败了\n");
			break;
		}
	}

}

int main()
{
	int a = 0;
	srand((unsigned int)time(NULL));
	do {

		printf("猜数字游戏，1~100\n");

		printf("*********************\n");
		printf("****1.play*******\n");
		printf("****0.exit*******\n");
		printf("*********************\n");
		printf("请选择\n");
		scanf("%d", &a);
		switch (a)
		{
		case 1:
			game();
			break;
		case 0:
			printf("exit");
			break;
		default:
			printf("选择错误，请重新选择\n");
			break;
		}
	} while (a);
	return 0;
}